﻿namespace Pps.Gui.Base
{
    public class Rectangle
    {
        public int X
        {
            get { return this.Position.X; }
        }

        public int Y
        {
            get { return this.Position.Y; }
        }

        public int Width
        {
            get { return this.Size.Width; }
        }

        public int Height
        {
            get { return this.Size.Height; }
        }

        /// <summary>
        /// Gets or sets the position.
        /// </summary>
        /// <value>
        /// The position.
        /// </value>
        public virtual Point Position
        {
            get;
            set;
        }

        /// <summary>
        /// Gets or sets the size.
        /// </summary>
        /// <value>
        /// The size.
        /// </value>
        public virtual Size Size
        {
            get;
            set;
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="Rectangle"/> struct.
        /// </summary>
        /// <param name="x">The x position.</param>
        /// <param name="y">The y position.</param>
        /// <param name="width">The width of the rectangle.</param>
        /// <param name="height">The height of the rectangle.</param>
        public Rectangle(int x, int y, int width, int height)
            : this(new Point(x, y), new Size(width, height))
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="Rectangle"/> class.
        /// </summary>
        /// <param name="x">The x.</param>
        /// <param name="y">The y.</param>
        /// <param name="size">The size.</param>
        public Rectangle(int x, int y, Size size)
            : this(new Point(x, y), size)
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="Rectangle"/> class.
        /// </summary>
        /// <param name="position">The position.</param>
        /// <param name="size">The size.</param>
        public Rectangle(Point position, Size size)
        {
            this.Position = position;
            this.Size = size;
        }

        /// <summary>
        /// Determines whether the position is in the rectangle.
        /// </summary>
        /// <param name="x">The x position.</param>
        /// <param name="y">The y position.</param>
        /// <returns>True if the position is in the rectangle.</returns>
        public bool Contains(int x, int y)
        {
            return (x >= this.X && y >= this.Y && x <= this.X + this.Width && y <= this.Y + this.Height);
        }

        /// <summary>
        /// Determines whether the position is in the rectangle.
        /// </summary>
        /// <param name="p">Point</param>
        /// <returns>True if the point is in the rectangle.</returns>
        public bool Contains(Point p)
        {
            return (p.X >= this.X && p.Y >= this.Y && p.X <= this.X + this.Width && p.Y <= this.Y + this.Height);
        }


        /// <summary>
        /// Returns a <see cref="System.String" /> that represents this instance.
        /// </summary>
        /// <returns>
        /// A <see cref="System.String" /> that represents this instance.
        /// </returns>
        public override string ToString()
        {
            return this.X.ToString() + ";" + this.Y.ToString() + " " + this.Width.ToString() + ";" + this.Height.ToString();
        }
    }
}